<template>
    <div>

        <h1>病房信息添加</h1>
         <table class="table">
             <tbody>
                <tr>
                    <td>病房名称</td>
                    <td>
                        <input type="text" v-model="data.houseName">
                    </td>
                </tr>
                <tr>
                    <td>所属科室</td>
                    <td>
                         <select v-model="data.ksid">
            <option :value="0">请选择科室</option>
            <option v-for="e in ksxlk" :value="e.id">{{ e.ksName }}</option>
        </select>
                    </td>
                </tr>
                <tr>
                    <td>床位总数量</td>
                    <td>
                        <input type="number" v-model="data.houseZS">
                    </td>
                </tr>
                <tr>
                    <td>病房状态</td>
                    <td>
                        <input type="checkbox" v-model="data.isState" checked> 选中为维修,未选中为启用
                    </td>
                </tr>
                <tr>
                    <td>空闲床数量</td>
                    <td>
                        <input type="number" v-model="data.houseKC">
                    </td>
                </tr>
                <tr>
                    <td>创建日期</td>
                    <td>
                        <input type="date" v-model="data.houseBFDate">
                    </td>
                </tr>
                <tr>
                    <td>床铺状态</td>
                    <td>
                        <input v-model="data.cpState" type="radio" :value=true  name=true checked>未满
                        <input v-model="data.cpState" type="radio" :value=false name=false >已住满
                    </td>
                </tr>
                <tr>
                    <td colspan="2">
                        <input type="button" value="添加病房" @click="add"> 
                    </td>
                </tr>
             </tbody>
        </table>
    </div>
</template>

<script setup lang="ts">
import {ref,onMounted} from 'vue'
import axios from 'axios'
import { useRouter } from 'vue-router'

const router=useRouter();
onMounted(()=>{
    KSXLKS();
})
//科室下拉框
const ksxlk=ref([{
    "id": 1,
    "ksName": "骨科",
    "kScount": 15,
    "ksms": "",
    "ksDate": "2025-05-30T00:00:00",
    "isDelete": true
}]) 
const KSXLKS=()=>{
    axios.get("/api/HouseKS/XLKks").then(res=>{
        ksxlk.value=res.data
    })
} 


const data=ref({
  "id": 0,
  "houseName": "",
  "ksid": 0,
  "houseZS": 0,
  "isState": true,
  "houseKC": 0,
  "houseBFDate": "2025-05-19T03:37:05.416Z",
  "cpState": true
})

const add=()=>{
    if(data.value.houseName=="")
{
    alert("病房名称不能为空");
    return;
}
if(data.value.houseName.length>6)
{
  alert("病房名称不能超过6个字符")
  return;
}
    axios.post("/api/HouseBF/AddHouseBF",data.value).then(res=>{
      if(res.data>0)
      {
        alert("添加成功")
        router.push({path:"/"})
      }
      else{
        alert("添加失败");
        return;
      }
    })
}

</script>

<style scoped>

</style>